package com.happy.study.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.happy.study.entity.DataEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DataMapper extends BaseMapper<DataEntity> {

    @Select ( value = "<script>SELECT di.*, ci.categoryName AS categoryName\n" +
            "FROM data_info di\n" +
            "         left join category_info ci on ci.id = di.categoryId\n" +
            "<where><if test='categoryId != null and categoryId != 0'>and di.categoryId=#{categoryId}</if>\n" +
            "</where> order by di.categoryId ASC limit #{start}, #{end}</script>" )
    List<DataEntity> queryList ( Integer categoryId, Integer start, Integer end );


    @Select ( value = "<script>SELECT COUNT(1)\n" +
            "FROM data_info di\n" +
            "         left join category_info ci on ci.id = di.categoryId\n" +
            "<where><if test='categoryId != null and categoryId != 0'>and di.categoryId=#{categoryId}</if>\n" +
            "</where></script>" )
    Integer queryCount ( Integer categoryId );

}
